﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using eschoolBO;

namespace ESCHOOL.teachers
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        calender c1 = new calender();
        protected void Page_Load(object sender, EventArgs e)
        {
            btnupdate.Visible = false;
            if (!IsPostBack)
            {
                for (int d = 1; d <= 31; d++)
                    ddldate.Items.Add(d.ToString());
                for (int yr = 1900; yr <= 2100; yr++)
                    ddlyr.Items.Add(yr.ToString());
                DataTable dt = c1.GetRecords(-99, "", "", false, " and ");
                GridView1.DataSource = dt;
                GridView1.DataBind();

            }

        }

     
       

       

        protected void btninst_Click(object sender, EventArgs e)
        {
            c1.calender_id=-99;
            DateTime dat=new DateTime(Convert.ToInt32(ddlyr.SelectedItem.ToString()),Convert.ToInt32(ddlmnth.SelectedValue.ToString()),Convert.ToInt32(ddldate.SelectedItem.ToString()));
            c1.date=dat.ToString();
            c1.event_name=txtevnt.Text;
            c1.isdeleted=false;
            c1.SaveRecords();
            Response.Redirect("~/teachers/TCurriculum.aspx");
            
        }

        protected void btnupt_Click(object sender, EventArgs e)
        {
         c1.calender_id=Convert.ToInt64(txtid.Text);
            DateTime dat=new DateTime(Convert.ToInt32(ddlyr.SelectedItem.ToString()),Convert.ToInt32(ddlmnth.SelectedValue.ToString()),Convert.ToInt32(ddldate.SelectedItem.ToString()));
            c1.date=dat.ToString();
            c1.event_name=txtevnt.Text;
            c1.isdeleted=false;
            c1.SaveRecords();
            Response.Redirect("~/teachers/TCurriculum.aspx");
           
            
        }

        protected void btnedit_Click(object sender, EventArgs e)
        {
           c1.calender_id = Convert.ToInt64(txtid.Text);
            DateTime dat = new DateTime(Convert.ToInt32(ddlyr.SelectedItem.ToString()), Convert.ToInt32(ddlmnth.SelectedValue.ToString()), Convert.ToInt32(ddldate.SelectedItem.ToString()));
           c1.date = dat.ToString();
           c1.event_name = txtevnt.Text; 
                c1.isdeleted = false;
            c1.SaveRecords();
            Response.Redirect("~/teachers/TCurriculum.aspx");
            
            
        }

        protected void btnedit_Command1(object sender, CommandEventArgs e)
        {
            btnupdate.Visible = true;
            btninsert.Visible = false;
            DataTable dt = c1.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", false, " and ");
            txtid.Text = dt.Rows[0]["calender_id"].ToString();
            DateTime dat = new DateTime();
            dat = Convert.ToDateTime(dt.Rows[0]["date"].ToString());
            ddldate.SelectedValue = dat.Day.ToString();
            ddlmnth.SelectedValue = dat.Month.ToString();
            ddlyr.SelectedValue = dat.Year.ToString();
            txtevnt.Text = dt.Rows[0]["event_name"].ToString();
            
        }

        protected void btndlt_Command(object sender, CommandEventArgs e)
        {
            DataTable dt =c1.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", false, " and ");
            c1.calender_id = Convert.ToInt64(dt.Rows[0]["calender_id"].ToString());
            c1.date = dt.Rows[0]["date"].ToString();
            c1.event_name = dt.Rows[0]["event_name"].ToString();
            c1.isdeleted = true;
            c1.SaveRecords();
            Response.Redirect("~/teachers/TCurriculum.aspx");
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            DataTable dt = c1.GetRecords(-99, "", "", false, " and ");
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }
}
